<template>
  <div class="header">
    <van-icon name="arrow-left" class="icon"  @click="back"  />
    <div>{{title}}</div>
    <div class="edit" v-if="edit" @click="editClick">
      {{store.state.edit?"编辑":"完成"}}
    </div>
  </div>
</template>

<script>
import { Toast } from 'vant';
import { useRouter } from "vue-router";
import { useStore } from 'vuex';
import emitter from "../common/js/eventbus.js"
export default {
    props:["title","edit"],
    setup(){
    const store = useStore();
    let router = useRouter();
    const back=()=>{
      router.back()
    }
    
    const editClick=()=>{
      if (store.state.cartlist.length) {
        store.commit("EDIT")
        emitter.emit("edit")
      }
      else{
        Toast.fail("购物车空空如也")
      }
    }

    return {
      back,
      editClick,
      store
    }
  }
}
</script>

<style lang="less" scoped>
.header{
    background-color: #fff;
    height: 40px;
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom:1px solid #d7d7d7 ;
    .edit {
        font-size: 16px;
        position: absolute;
        right: 15px;
        font-weight: normal;
    }
    .icon{
        position: absolute;
        left: 10px;
    }
}
</style>